package com.yixun.qfbao.hander;

import com.yixun.qfbao.apidto.RecommenderChangeReqDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.model.RecommenderChange;
import com.yixun.qfbao.service.RecommenderChangeService;
import com.yixun.qfbao.vo.RecommenderChangeReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @program: channel-parent
 * @description: 变更推荐人
 * @author: jhsong
 * @create: 2020-10-9
 **/
@Service("recommenderChangeHander")
public class RecommenderChangeHander extends CommonAbstractHander {

    @Autowired
    RecommenderChangeService recommenderChangeService;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        RecommenderChangeReqVo req = (RecommenderChangeReqVo)reqDto;
        RecommenderChangeReqDto reqDto1 = req.getParams();
        BaseResponseDTO resDto = new BaseResponseDTO();
        resDto.setResult(ResultEnum.FAIL.getNo());
        resDto.setErrorMsg("变更推荐人失败!");
        if(Objects.isNull(reqDto1.getCustomerPremisesId())
        || StringUtils.isBlank(reqDto1.getRecommenderUuid())){
            return resDto;
        }

        RecommenderChange recommenderChange = new RecommenderChange();
        recommenderChange.setCpId(reqDto1.getCustomerPremisesId());
        recommenderChange.setNewRecommender(reqDto1.getRecommenderUuid());
        Boolean flag = recommenderChangeService.recommenderChange(recommenderChange);
        if(flag){
            resDto.setResult(ResultEnum.SUCCESS.getNo());
            resDto.setErrorMsg("变更推荐人成功!");
        }
        return resDto;
    }

}
